//========================================================================
// *作者：海盗猫  主页：ilplay.com
// *脚本：UIFrameStore
// *描述：缓存管理脚本的基类
// *?2021 MYJL . All rights reserved.
//* ======================================================================

using System.Collections.Generic;
using UnityEngine;

namespace HDMCode.UIFrame
{
    public class UIFrameStore
    {
        /// <summary>
        /// 用于保存无论是否隐藏的所有UI
        /// </summary>
        public Dictionary<string, UIDisplay> allUIDict ;

        /// <summary>
        /// 用于保存不同类型的正在显示的UI
        /// </summary>
        public Dictionary<WrapperType, (Dictionary<string, UIDisplay> standard, Stack<UIDisplay> queue)> uiStoreDict;
        public (Dictionary<string, UIDisplay> standard, Stack<UIDisplay> queue) fixationMate;
        public (Dictionary<string, UIDisplay> standard, Stack<UIDisplay> queue) fullScreenMate;
        public (Dictionary<string, UIDisplay> standard, Stack<UIDisplay> queue) informMate;
        public (Dictionary<string, UIDisplay> standard, Stack<UIDisplay> queue) dialogMate;

        public void InitStoreDate() 
        {
            uiStoreDict = new Dictionary<WrapperType, (Dictionary<string, UIDisplay> standard, Stack<UIDisplay> queue)>();
            fixationMate = (new Dictionary<string, UIDisplay>(), new Stack<UIDisplay>());
            fullScreenMate = (new Dictionary<string, UIDisplay>(), new Stack<UIDisplay>());
            informMate = (new Dictionary<string, UIDisplay>(), new Stack<UIDisplay>());
            dialogMate = (new Dictionary<string, UIDisplay>(), new Stack<UIDisplay>());
            allUIDict = new Dictionary<string, UIDisplay>();
            uiStoreDict.Add(WrapperType.Dialog, dialogMate);
            uiStoreDict.Add(WrapperType.inform, informMate);
            uiStoreDict.Add(WrapperType.Fixation, fixationMate);
            uiStoreDict.Add(WrapperType.FullScreen, fullScreenMate);
        }

        /// <summary>
        /// 获取相应类型的存储数据
        /// </summary>
        /// <param name="wrapperType"> 窗口类型 </param>
        /// <param name="readStore"> 获取的储存数据 </param>
        /// <returns>返回是否成功</returns>
        protected bool ReadStore(WrapperType wrapperType, out (Dictionary<string, UIDisplay> standard, Stack<UIDisplay> queue) readStore)
        {
            if (uiStoreDict.TryGetValue(wrapperType, out readStore))
                return true;
            else
                Debug.LogWarning($" UIFrame 未找到相应的 WrapperType 存储位置 -- 类型：[{wrapperType}】！");
            return false;
        }
    }
}
